#!/usr/bin/python
# author: andreas.kuntz@gmail.com
# you found this code on http://yoshiii-box.googlecode.com/svn/ 
#

import datetime, Tkinter, time, threading

goal = datetime.datetime(2005, 11, 22, 14)	# da vortrag sophie
goal = datetime.datetime(2005, 12, 05, 8)	# recruting workshop
goal = datetime.datetime(2006, 3, 31, 12)	# meine DA abgabe!


def update(goal, tkdiff, tknow):
    while not exit_thread:
        now  = datetime.datetime.now()
        diff = goal - now
        now, rest = str(now).split('.', 1)
        tknow.set('now: '+now)
        diff, rest = str(diff).split('.', 1)
        tkdiff.set('left: '+diff)
        time.sleep(1)

def main():
    global exit_thread
    exit_thread = False
    
    root = Tkinter.Tk()
    root.title('keine Panik!')
    diff = Tkinter.StringVar()
    now  = Tkinter.StringVar()
           
    Tkinter.Label(root, text='goal:  '+str(goal)).pack()
    Tkinter.Label(root, textvar = now).pack()
    Tkinter.Label(root, textvar = diff).pack()

    threading.Thread(target=update, args=(goal, diff, now)).start()
    
    root.mainloop()
    exit_thread = True
    while threading.activeCount() > 2:
        time.sleep(1)

if __name__ == '__main__':
    main()
